package com.medica.ledproject.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.medica.ledproject.common.CustomException;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>
 * 
 * </p>
 *
 * @author xiaona
 * @since 2024-05-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("dz_park_led_programs")
@Tag(name="DzParkLedPrograms对象", description="")
public class DzParkLedPrograms implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @Schema(description = "节目名称")
    private String name;
    @Schema(description = "0 文字  1图片  2视频")
    private Integer type;
    @Schema(description = "创建用户")
    private Integer adminId;
    @Schema(description = "led屏幕id")
    private Integer ledId;
    @Schema(description = "灯杆id")
    private Integer lampId;

    @Schema(description = "文字内容")
    private String textContent;

    @Schema(description = "文字样式")
    private String textStyle;

    @Schema(description = "图片地址")
    private String picUrl;

    @Schema(description = "视频地址")
    private String videoUrl;

    @Schema(description = "显示区域,x,y,width,height",example = "0,0,15,25")
    private String area="0,0,1450,1450";

    @Schema(description = "动画效果")
    private String animation;

    @Schema(description = "停留时间")
    private Integer stayTime;

    @Schema(description = "1：正在执行  0：未执行 -1 已删除")
    private Integer state;

    private LocalDateTime ctime;

    private LocalDateTime uptime;

    public void setInfo(ReDzParkLedPrograms info) {
        if(StringUtils.isEmpty(info.getName())){
            throw new CustomException("名称不能为空！");
        }
        if(info.getType()==null){
            throw new CustomException("类型不能为空！");
        }
        if(info.getType()==0&&StringUtils.isEmpty(info.getTextContent())){
            throw new CustomException("文字类型的节目，文字不能为空！");
        }
        if(info.getType()==1&&StringUtils.isEmpty(info.getPicUrl())){
            throw new CustomException("图片类型的节目，图片地址不能为空！");
        }
        if(info.getType()==2&&StringUtils.isEmpty(info.getVideoUrl())){
            throw new CustomException("视频类型的节目，视频地址不能为空！");
        }
        this.name = info.getName();
        this.type = info.getType();
        this.textContent = info.getTextContent();
        this.textStyle = info.getTextStyle();
        this.picUrl = info.getPicUrl();
        this.videoUrl = info.getVideoUrl();
        this.area = info.getArea();
        this.animation = info.getAnimation();
        this.adminId = info.getAdminId();
        this.stayTime = info.getStayTime();
        this.ctime=LocalDateTime.now();
        if(type==0) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                this.textStyle = mapper.writeValueAsString(info.getFontStyle());
            } catch (Exception e) {
                e.printStackTrace();
                throw new CustomException(e.getMessage());
            }
        }
    }
}
